package UserView;

import Model.Student;
import Service.servicelmpl.StudentServicelmpl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class UseUi {
    public static int num = 0;
    public static int id = 1;

    public void UI() {
        //数据仓库
        Student[] stus = new Student[100];
        //Student zhang = new Student();
        StudentServicelmpl studentService = new StudentServicelmpl();

        boolean flag = true;
        while (flag) {
            System.out.println("1.查询所有学生信息");
            System.out.println("2.添加学生信息");
            System.out.println("3.删除学生信息");
            System.out.println("4.修改学生信息");
            System.out.println("0.退出系统");

            System.out.println("请输入你的业务数字");
            Scanner scanner = new Scanner(System.in);
            int num = scanner.nextInt();
            switch (num) {
                case 1:
                    studentService.showStu(stus, UseUi.num);
                    break;
                case 2:
                    Student zhang = new Student();
                    System.out.println("请输入学生姓名");
                    String name = scanner.next();

                    System.out.println("请输入学生性别");
                    String sex= scanner.next();

                    System.out.println("请输入学生年龄");
                    Integer age = scanner.nextInt();

                    System.out.println("请输入学生专业");
                    String major = scanner.next();
                    zhang.setId(UseUi.id++);
                    zhang.setName(name);
                    zhang.setSex(sex);
                    zhang.setAge(age);
                    zhang.setMajor(major);

                    Date date = new Date();
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String format= simpleDateFormat.format(date);

                    zhang.setTime(format);
                    studentService.addStu(stus, zhang);
                    break;
                case 3:
                    System.out.println("请输入你要删除的学号");
                    int stuId = scanner.nextInt();
                    Boolean b=studentService.delStu(stus,UseUi.num,stuId);
                    if (b!=null) {
                        if (b) {
                            System.out.println("删除成功");
                            UseUi.num--;
                        } else {
                            System.out.println("删除的不存在");
                        }
                    }
                    break;
                case 4:
                    System.out.println("请输入你要修改的学号：");
                    int stuId1 = scanner.nextInt();
                    studentService.updateStu(stus,UseUi.num,stuId1);
                    break;
                case 0:
                    System.out.println("退出系统");
                    flag = false;
                    break;
            }
        }
    }
}
